package com.example.demo2.generator.service.impl;

import com.example.demo2.generator.entity.CarList;
import com.example.demo2.generator.mapper.CarListDao;
import com.example.demo2.generator.service.CarListService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆列表(CarList)表服务实现类
 *
 * @author makejava
 * @since 2024-09-18 11:28:22
 */
@Service("carListService")
public class CarListServiceImpl implements CarListService {
    @Resource
    private CarListDao carListDao;

    /**
     * 通过ID查询单条数据
     *
     * @param carListId 主键
     * @return 实例对象
     */
    @Override
    public CarList queryById(Integer carListId) {
        return this.carListDao.queryById(carListId);
    }

//    /**
//     * 分页查询
//     *
//     * @param carList 筛选条件
//     * @param pageRequest      分页对象
//     * @return 查询结果
//     */
//    @Override
//    public Page<CarList> queryByPage(CarList carList, PageRequest pageRequest) {
//        long total = this.carListDao.count(carList);
//        return new PageImpl<>(this.carListDao.queryAllByLimit(carList, pageRequest), pageRequest, total);
//    }

    /**
     * 新增数据
     *
     * @param carList 实例对象
     * @return 实例对象
     */
    @Override
    public CarList insert(CarList carList) {
        this.carListDao.insert(carList);
        return carList;
    }

    /**
     * 修改数据
     *
     * @param carList 实例对象
     * @return 实例对象
     */
    @Override
    public CarList update(CarList carList) {
        this.carListDao.update(carList);
        return this.queryById(carList.getCarListId());
    }

    /**
     * 通过主键删除数据
     *
     * @param carListId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer carListId) {
        return this.carListDao.deleteById(carListId) > 0;
    }

    @Override
    public List<CarList> queryAllCarList() {
        return this.carListDao.queryAllCarList();
    }

    @Override
    public List<CarList> queryAllByLimit(CarList carList) {
        return this.carListDao.queryAllByLimit(carList);
    }

    @Override
    public int deleteBatch(List<CarList> list) {
        return carListDao.deleteBatch(list);
    }


}
